import api.utils.ToolsAPI;
import bean.GetCenterDetailBean;
import bean.SuccessBean;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 生产管理
 */
public class ProductionManagement<T> extends ToolsAPI<T> {

    @Test(description = "生产管理-页面数据", enabled = true, priority = 0)
    public void getCenterDetail() {
        GetCenterDetailBean bean = runAPI(retrofit.getCenterDetail(), "getCenterDetail");
        assertFalse(bean.getData().getLineName().equals(""), "产线名称不能为空");
        assertFalse(bean.getData().getShiftName().equals(""), "不能为空");
        assertFalse(bean.getData().getWorkingProcessEquipments().size() <= 0, "产线设备列表数据为空");
    }

    @Test(description = "停止产线")
    public void stopLine() {
        put("lineId",1);
        put("action",0);
        SuccessBean bean = runAPI(retrofit.changeLineState(toBody(map)));
        assertFalse(!bean.getMessage().equals("成功"), "停止产线失败stopLine");
        GetCenterDetailBean getCenterDetailBean = runAPI(retrofit.getCenterDetail());
        assertTrue(getCenterDetailBean.getData().getLineStatusCode()==0,"停止产线失败getCenterDetail");
    }

    @Test(description = "启动产线")
    public void startLine() {
        put("lineId",1);
        put("action",1);
        SuccessBean bean = runAPI(retrofit.changeLineState(toBody(map)));
        assertFalse(!bean.getMessage().equals("成功"), "启动产线失败stopLine");
        GetCenterDetailBean getCenterDetailBean = runAPI(retrofit.getCenterDetail());
        assertTrue(getCenterDetailBean.getData().getLineStatusCode()==1,"启动产线失败getCenterDetail");
    }

    @Test(description = "换刀后产线状态-停止", enabled = true, priority = 0)
    public void changeKnifeLogAdd_stop() {
        //{"lineId":1,"items":[{"equipmentName":"毛坯备料设备-勿删","equipmentId":1,"knifeNumber":"1231"}]}
        List<Map<String, Object>> items = new ArrayList<>();
        Map<String, Object> itemsMap = new HashMap<>();
        itemsMap.put("equipmentId", 1);
        itemsMap.put("equipmentName", "毛坯备料设备-勿删");
        itemsMap.put("knifeNumber", "1231");
        items.add(itemsMap);
        put("lineId", 1);
        put("items", items);
        SuccessBean bean = runAPI(retrofit.changeKnifeLogAdd(toBody(map)));
        assertTrue(bean.getMessage().equals("成功"), "换刀失败");
        GetCenterDetailBean getCenterDetailBean = runAPI(retrofit.getCenterDetail());
        assertTrue(getCenterDetailBean.getData().getLineStatusCode()==0,"换刀后产线状态应该为停止");
    }
}
